package xyz.jcat.sat.gateway;

import cn.dev33.satoken.stp.StpUtil;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import xyz.jcat.common.web.Resp;
import xyz.jcat.sat.admin.api.IAdminService;
import xyz.jcat.sat.admin.api.dto.AdminLoginDto;
import xyz.jcat.sat.admin.api.vo.AdminLoginSuccessVo;

@RestController
public class LoginController {

    @DubboReference
    private IAdminService adminService;

    @PostMapping("/sat/admin/login")
    public Resp adminLogin(@RequestBody AdminLoginDto adminLoginDto) {
        AdminLoginSuccessVo vo = adminService.login(adminLoginDto);
        String token = StpUtil.createLoginSession(vo.getUserId());
        return Resp.ok(token);
    }

    @PostMapping("/sat/admin/logout")
    public Resp logout() {
        StpUtil.logout();
        return Resp.ok();
    }

}
